<?php include("cabeca.php"); 

	include("connection.php");
	if ($_POST['genero']){
 		$query = "SELECT * FROM `filme` NATURAL JOIN `filme_genero` WHERE CONVERT(`Genero` USING utf8 )='".$_POST['genero']."'";
	} else {
		if ($_POST['nome']) {
			$query = "SELECT * FROM `filme` WHERE CONVERT(`Nome` USING utf8) ='".$_POST['nome']."'";
		} else {
			if ($_GET['q']){
				$query = "SELECT * FROM `filme` NATURAL JOIN `filme_genero` WHERE CONVERT(`Genero` USING utf8 )='".$_GET['q']."'";
			} else {
				$query = "SELECT * FROM  `filme`";
			}
		}
	}
	$result = mysql_query($query);
	
	echo "<ul>";
	
	while ($row = mysql_fetch_array($result)) {
		echo "<li>";
		echo "<h2>".$row['Nome']."</h2><i>(Dura&ccedil;&atilde;o: ".$row['Duracao']."m)</i><br>";
		echo "Ano: ".$row['AnoLancamento']."<br>";
		echo "<p>".$row['Sinopse']."</p>";
		echo "<a href='http://www.imdb.com/title/tt".$row['IMDB']."/'>Link IMDB</a><br />";
		$estoque = $row['QTN'];
		if ($estoque != 0) {
		?>
        <form method="post" action="alugar.php">
        	<?php echo "<input type='hidden' name='id' value='".$row['IMDB']."' />" ?>
        	<input type="submit" value="Alugar este filme" />
        </form>
        <?php } else {
			echo "Todos os DVDs alugados";
		}
		echo "<br /><br />";
		echo "</li>";
	}
	
	echo "</ul>";

	
	mysql_close($conn);

include("pe.php"); ?>